<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ page import="object.User" %>
<%@ page import="Dao.UserDaoImpt" %>

<html>
<head>
    <title>正在返回登录界面</title>
</head>
<body>
<%
    UserDaoImpt dao = new UserDaoImpt();
    User user = new User();
    user.updateUname(request.getParameter("uname"));
    user.updateUpwd(request.getParameter("upwd"));
    user.updateUtype(request.getParameter("identity"));
    String use_type = request.getParameter("use_type");
    if (use_type.equals("返回")) {
        response.sendRedirect("login.jsp");
    } else if (use_type.equals("提交")) {
        if (dao.SelectUser(user)) {
            out.println("<script>alert('用户名重复，正在返回注册页面')</script>");
            response.setHeader("refresh", "0;URL=enrol.jsp");
        } else {
            if (dao.AddUser(user) == 1) {
                out.println("<script>alert('注册成功，正在返回登录页面')</script>");
                response.setHeader("refresh", "0;URL=login.jsp");
            } else {
                out.println("<script>alert('注册失败，正在返回注册页面')</script>");
                response.setHeader("refresh", "0;URL=enrol.jsp");
            }
        }
    } else {
        response.sendRedirect("Error.jsp?message=Invalid credentials");
    }
%>
</body>
</html>
